package com.kele.demo.utils;

/**
 * @author chunhui.li
 * @date 2022/2/11 14:02
 * @Description
 * @ClassName RequestResultUtil
 */
public class RequestResultUtil {

    /**
     * 返回成功带上数据
     * @param obj 返回数据
     */
    public static RequestResult success(Object obj){
        RequestResult requestResult = new RequestResult();
        requestResult.setCode(0);
        requestResult.setMessage("success");
        requestResult.setServiceId(GetModuleEnvUtil.getEnvServiceId());
        requestResult.setData(obj);
        return requestResult;
    }

    /**
     * 返回成功不带上数据
     */
    public static RequestResult success(){
        RequestResult requestResult = new RequestResult();
        requestResult.setCode(0);
        requestResult.setMessage("success");
        requestResult.setServiceId(GetModuleEnvUtil.getEnvServiceId());
        requestResult.setData(null);
        return requestResult;
    }

    /**
     * 返回错误，自定义错误码和错误信息
     * @param code 状态码
     * @param msg 错误信息
     */
    public static RequestResult error(Integer code, String msg) {
        RequestResult requestResult = new RequestResult();
        requestResult.setCode(code);
        requestResult.setMessage(msg);
        requestResult.setServiceId(GetModuleEnvUtil.getEnvServiceId());
        return requestResult;
    }

}
